package greedy;

/**
 * Created with IntelliJ IDEA.
 * Description: 122. 买卖股票的最佳时机 II
 * User: Li_yizYa
 * Date: 2025/6/24
 * Time: 21:31
 */
public class Solution4 {
    public int maxProfit(int[] prices) {
        if (prices == null || prices.length == 0) {
            return Integer.MIN_VALUE;
        }
        if (prices.length == 1) {
            return 0;
        }
        int ret = 0;
        for (int i = 1; i < prices.length; i++) {
            int cur = prices[i] - prices[i - 1];
            if (cur > 0) {
                ret += cur;
            }
        }
        return ret;
    }
}
